package thread;

import java.util.Random;

public class HomeWork1 {
    public static long count1 = 0;
    public static long count2 = 0;
    public static void main(String[] args) throws InterruptedException {
        long st = System.currentTimeMillis();
        long[] a = new long[10000000];
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            a[i] = r.nextInt(100);
        }
        Thread t1 = new Thread(()->{
            for (int i = 0; i < a.length; i+=2) {
                count1+=a[i];
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 1; i < a.length; i+=2) {
                count2+=a[i];
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("count1:"+count1);
        System.out.println("count2:"+count2);
        System.out.println("count:"+(count1+count2));
        long en = System.currentTimeMillis();
        System.out.println("time:"+(en-st)+"ms");
    }
}
